<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/auth/api/userinfo.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/questionview.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/question.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/answer.js"></script>
    <script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
    <script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>咨询管理</cite></a>
			<a><cite>咨询管理</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid" id="content">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;" @submit.prevent>
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="开始日" name="start" id="start"></div>-->
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="截止日" name="end" id="end"></div>-->
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛区</div>
							<select name="division">
								<option v-for="zone in zoneList" :value="zone.id">{{zone.zoneName}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5" style="width: 40px;">账号</div>
							<input type="text" name="number" placeholder="账号" autocomplete="off" class="layui-input"></div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div class="layui-card-body"  v-cloak>
					<table class="layui-table layui-form" id="table">
						<span>本页共计{{total}}条数据</span>
						实际共有数据<span id="mysum"></span>条
					</table>
					<section id="page" style="visibility: hidden;"></section>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script type="text/html" id="operating">
<a href="javascript:;" onclick="xadmin.open('回复','reply.html?type=question&questionId='+{{d.questionId}},600,400)" class="layui-table-link">回复</a>
</script>
<script>
	var app=new Vue({
		el: '#content',
		data: {
			accountList:[],
			userInfoList:[],
			zoneList:[],
			matchList:[],
			listQuestion:[],
			listAnswer:[],
			list:[],
			total: 0,
			pageSize: 500,
			pageNo: 1,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{field: 'questionId', title: '序号', width: 80},
				{field: 'userName', title: '用户名'},
				{field: 'account', title: '账号'},
				{field: 'matchName', title: '赛项'},
				{field: 'zoneName', title: '赛区'},
				{field: 'question', title: '提问内容'},
				{field: 'createTime', title: '提问时间'},
				{field: 'answer', title: '回复内容'},
				{field: 'answerTime', title: '回复时间'},
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		mounted: function() {
			var vm = this
			vm.loadMath();
			vm.loadZone();
			//帐号查询
				var queryData = {
				    page:{
				        current: vm.pageNo, //当前页数
				        size:vm.pageSize   //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象

	                    }
				    }
				};
			vm.loadQuestion(queryData);
			layui.use('form', function () {
				vm.form = layui.form;
				var that=vm
				vm.getData()
				vm.form.on('submit(search)', function (data) {
					console.log(data)
					app.list = []
					app.queryByAccount1(data.field.division,data.field.number)
					setTimeout(function(){
						var table = layui.table
						vm.total = that.list.length
						that.list=that.list.reverse()
						 // alert(JSON.stringify(that.list))
						var list=[]
						for (i=0;i<that.list.length;i++){
							 if (that.list[i].account==data.field.number){
								   list.push(that.list[i])
							 }
						}
						that.list=list
						//头工具栏事件
						table.render({
							elem: '#table',
							title: '用户数据表',
							cols: [that.cols],
							data: that.list,
							count:app.listQuestion.total
						})
					},2000)
					// layer.msg(JSON.stringify(data.field), function () {
					// location.href = 'index.html'
					// })
					return false
				})
			});
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				xadmin.add_tab(name,url)
			},
			loadMath:function(){
				var vm = this
				TmatchqueryList({},function(data){
					vm.matchList=data
				},function(status,message){
					alert(message);
				})
			},
			loadZone:function(){
				var vm = this
				ZonequeryList({},function(data){
					vm.zoneList=data
				},function(status,message){
					alert(message);
				})
			},
			loadAccount:function(varParam){
				var vm = this
				AccountqueryList(varParam,function(data){
					vm.accountList=data
				},function(status,message){

				})
			},
			loadUserInfo:function(varParam){
				var vm = this
				UserInfoqueryList(varParam,function(data){
					vm.userInfoList=data
				},function(status,message){

				})
			},
			queryByAccount:function(varAccount){
				//帐号查询
				var queryData = {
				    page:{
				        current: this.pageNo, //当前页数
				        size:this.pageSize   //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
				        	userName:varAccount
	                    }
				    }
				};
				this.loadQuestion(queryData)
			},
			queryByAccount1:function(zoneId,varAccount){
				// alert(varAccount)
				// alert(zoneId)
				//帐号查询
				var queryData = {
						page:{
								current: this.pageNo, //当前页数
								size:this.pageSize   //每页长度
						},
						cond:{ //条件
								eq:{ // 多条件对象
									userName:varAccount
											}
						}
				};
				if (zoneId!=undefined&&zoneId!=null&&zoneId!=''){
					var queryData = {
							page:{
									current: this.pageNo, //当前页数
									size:this.pageSize   //每页长度
							},
							cond:{ //条件
									eq:{ // 多条件对象
										zoneId:zoneId
												}
							}
					};
				}



				this.loadQuestion1(queryData)
			},
			loadQuestion1:function(varParam){
				var vm = this

				QuestionPageList(varParam,function(data){
          // alert(JSON.stringify(data))

					vm.listQuestion.records=data.records;

					var answerParam={
						in:{
							  data:[],
								attrName:"question_id"
							}
					}
					var accountParam={
						in:{
								data:[],
								attrName:"id"
							}
					}
					if(vm.listQuestion.records.length == 0){
						return;
					}
					for(var i=0; i<vm.listQuestion.records.length; ++i){
						// alert(vm.listQuestion.records[i].id)
						answerParam.in.data.push(vm.listQuestion.records[i].id)
						accountParam.in.data.push(vm.listQuestion.records[i].userId)
					}
					vm.loadAccount(accountParam);
					vm.loadUserInfo(accountParam);
					vm.loadAnswer(answerParam);
				},function(status,message){

				})
			},

			loadQuestion:function(varParam){
				var vm = this

				QuestionqueryList(varParam,function(data){
document.getElementById("mysum").innerHTML=data.length
					vm.listQuestion.records=data;

					var answerParam={
						in:{
								data:[],
								attrName:"question_id"
							}
					}
					var accountParam={
						in:{
								data:[],
								attrName:"id"
							}
					}
					if(vm.listQuestion.records.length == 0){
						return;
					}
					for(var i=0; i<vm.listQuestion.records.length; ++i){
						// alert(vm.listQuestion.records[i].id)
						answerParam.in.data.push(vm.listQuestion.records[i].id)
						accountParam.in.data.push(vm.listQuestion.records[i].userId)
					}
					vm.loadAccount(accountParam);
					vm.loadUserInfo(accountParam);
					vm.loadAnswer(answerParam);
				},function(status,message){

				})
			},
			getAccountFromMem:function(varIds){
				for(var i=0;i<this.accountList.length;++i){
					if(this.accountList[i].id == varIds){
						return this.accountList[i].userName;
					}
				}
				return null;
			},
			getUserNameFromMem:function(varIds){
				for(var i=0; i<this.userInfoList.length; ++i){
					if(this.userInfoList[i].id == varIds){
						return this.userInfoList[i].name
					}
				}
				return null;
			},
			getMatchName:function(varMatchId){
				for(var i=0; i<this.matchList.length; ++i){
					if(this.matchList[i].id == varMatchId){
						return this.matchList[i].theme;
					}
				}
				return null;
			},
			getZoneName:function(varZoneId){
				for(var i=0; i<this.zoneList.length; ++i){
					if(this.zoneList[i].id==varZoneId){
						return this.zoneList[i].zoneName;
					}
				}
				return null;
			},
			getAnswerFromMem:function(varQuestionId){
				for(var i=0;i<this.listAnswer.length;++i){
					if(this.listAnswer[i].questionId == varQuestionId){
						return this.listAnswer[i];
					}
				}
				return null;
			},
			loadAnswer:function(varAnswerParam){
				var vm = this
				AnswerqueryList(varAnswerParam,function(data){
					vm.listAnswer=data;

					vm.list = []
					for(var i=0;i<vm.listQuestion.records.length;++i){
						var listItem={
							questionId:vm.listQuestion.records[i].id,
							index:i+(vm.listQuestion.current-1)*vm.listQuestion.size,
							account:vm.getAccountFromMem(vm.listQuestion.records[i].userId),
							userName:vm.getUserNameFromMem(vm.listQuestion.records[i].userId),
							matchName:vm.getMatchName(vm.listQuestion.records[i].matchId),
							zoneName:vm.getZoneName(vm.listQuestion.records[i].zoneId),
							question:vm.listQuestion.records[i].content,
							createTime:vm.listQuestion.records[i].time
						}
						var varAnswer = vm.getAnswerFromMem(vm.listQuestion.records[i].id);
						if(varAnswer != null){
							listItem.answer=varAnswer.content;
							listItem.answerTime=varAnswer.time;
						}else{
							listItem.answer="--";
							listItem.answerTime="--";
						}

						vm.list.push(listItem)
					}
				},function(status,message){

				})
			},
			getData(){
				this.init()
			},
			init:function() {
				var that = this
				var vm = this
				layui.use(['laypage','table'], function () {
					var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
					var table = layui.table

					that.list=that.list.reverse()
					var funTool = fun_tool();
					app.zoneList=funTool.getAdminZoneIds();
					var zlist=[]
					for (i=0;i<app.zoneList.length;i++){
						zlist.push(app.zoneList[i].zoneName)
					}
					var zlist1=zlist.toString()
					var list=[]
					for (i=0;i<that.list.length;i++){
						  if (zlist1.indexOf(that.list[i].zoneName)>-1){
								list.push(that.list[i])
							}
					}
					that.list=list
						vm.total = that.list.length
					//头工具栏事件
					// table.render({
					// 	elem: '#table',
					// 	title: '用户数据表',
					// 	cols: [that.cols],
					// 	data: that.list,
					// 	count:app.listQuestion.total
					// })
					laypage.render({
						elem: 'page',
						count: vm.total,
						current: vm.pageNo,
						limit: vm.pageSize,
						jump: function (obj, first) {
							// alert(JSON.stringify(obj))
							// if (first) return
							vm.pageNo = obj.curr
							// vm.getData()
							vm.queryByAccount1()
							setTimeout(function(){
								var table = layui.table
								vm.total = that.list.length
								that.list=that.list.reverse()

								//头工具栏事件
								table.render({
									elem: '#table',
									title: '用户数据表',
									cols: [that.cols],
									data: that.list,
									count:app.listQuestion.total,
									page: true,
								})
							},1000)
						}
					})
					var form = layui.form
					// form.on('submit(search)', function (data) {
					// 	console.log(data)
					// 	app.queryByAccount(data.field.accountValue)
					// 	// layer.msg(JSON.stringify(data.field), function () {
					// 	// location.href = 'index.html'
					// 	// })
					// 	return false
					// })
				})
			}
		}
	})
</script>
</html>
